home *** CD-ROM | disk | FTP | other *** search
Wrap
property channel, cell, Xloc, Yloc, cellObject, lastMove, newMove, nextCell, nextCellObject, firstCell, startDirection, blockedCell, blockedCellObj, exitBridgeDir, invisibleButtonList, previousCell, buildingSound, status, animationScript, rotationSteps, currentState, animCounter, Xincrement, Yincrement, pixelsToMove, tempo, programmedMove, latestMove, playBack, playBackCounter global gSimObject, gGasGaugeObject, gLevelObject, gTruckObject, gMenuObject, gActorList, gCDpath, gFileSep on birth me set channel to the truckSprite of gSimObject return me end on initTruckProps me, firstTruckCell, direction set status to #idle set programmedMove to 0 set firstCell to firstTruckCell set cell to firstCell set previousCell to the startCell of gSimObject set startDirection to direction set newMove to startDirection set lastMove to startDirection set x to blockCrossings(the startCell of gSimObject, startDirection) set cellObject to getAt(the cellList of gSimObject, cell) set Xloc to the Xloc of cellObject set Yloc to the Yloc of cellObject set the startTileNum of cellObject to getProp(the partialTileList of gSimObject, startDirection) set the startTileType of cellObject to #Road set the tileNum of cellObject to the startTileNum of cellObject set the tileType of cellObject to #Road set the recordedMoveList of gSimObject to [startDirection] set playBack to 0 end on moveTruck me, moveInput set latestMove to moveInput surroundStaticSprite(gSimObject, previousCell, cell) set the locH of sprite the underTruckSprite of gSimObject to 1000 updateStage() if the demoFlag of gSimObject <> 1 then hideInvisibleButtons(gSimObject) end if surroundStaticSprite(gSimObject, cell, cell) updateStage() set whatType to the tileType of getAt(the cellList of gSimObject, cell + getProp(the moveList of gSimObject, latestMove)) if (whatType = #immovable) or (whatType = #Building) then rumbleAndShake(me, lastMove, latestMove) else set newMove to latestMove add(the recordedMoveList of gSimObject, newMove) set nextCell to cell + getProp(the moveList of gSimObject, newMove) set nextCellObject to getAt(the cellList of gSimObject, nextCell) surroundSprite(cell, newMove) if the demoFlag of gSimObject = 1 then lightButton(gSimObject, newMove) end if fillRoadTile(newMove) redrawCell(nextCellObject, the destinationSprite of gSimObject) updateStage() rotateSprite(me, lastMove, newMove) end if end on afterRotating me set status to #idle if the demoFlag of gSimObject = 1 then unlightButton(gSimObject, newMove) end if if the tileType of nextCellObject <> #BG then set programmedMove to 0 set blockedCell to nextCell set blockedCellObj to nextCellObject unpuppetAll() hideSprites(gSimObject) clearAllActors() repeat with obstacleType in [#Rocks, #Valley, #River] if the tileType of nextCellObject = obstacleType then set the obstacleState of gSimObject to obstacleType keepSandboxBut(the sandboxChan of gSimObject) puppetPalette("SimPal") go("Grass") go(the frame + 1) if obstacleType = #River then puppetPalette("RiverPal", 60) else if obstacleType = #Valley then puppetPalette("DitchPal", 60) else puppetPalette("DynoPal", 60) end if end if updateStage() puppetPalette(0) go(string(obstacleType)) puppetSprite(48, 0) exit repeat end if end repeat flushBuffer() abort() else blockCrossings(cell, newMove) part2ofMove(me) flushBuffer() end if end on part2ofMove me set lastMove to newMove goToNextCell(me) end on goToNextCell me if (newMove = #n) or (newMove = #s) or (newMove = #E) or (newMove = #w) then set pixelsToMove to the cellHeight of gSimObject set tempo to 60 else set pixelsToMove to the cellHalfV of gSimObject set tempo to 40 end if set deltaList to getProp(the deltaList of gSimObject, newMove) set Xincrement to getAt(deltaList, 1) set Yincrement to getAt(deltaList, 2) set status to #animating set animCounter to 1 set animationScript to "moveLinear( gTruckObject )" if playBack then moveLinear(me) end if end on moveLinear me if animCounter <= pixelsToMove then set the locH of sprite channel to Xloc + (animCounter * Xincrement) set the locV of sprite channel to Yloc + (animCounter * Yincrement) set animCounter to animCounter + 1 puppetTempo(tempo) else set status to #idle set Xloc to the Xloc of nextCellObject set Yloc to the Yloc of nextCellObject if the finishedFlag of gSimObject = 0 then set connectedBuildingCell to checkForConnection() end if set previousCell to cell set cell to nextCell set cellObject to nextCellObject if (the level of gLevelObject = 3) and (the finishedFlag of gSimObject <> 1) then reduceGasGauge(gGasGaugeObject) updateGasGauge(gGasGaugeObject) updateStage() end if afterArrival(me, connectedBuildingCell) end if end on afterArrival me, connectedBuildingCell if playBack then set lastMove to newMove surroundStaticSprite(gSimObject, previousCell, cell) set the locH of sprite the underTruckSprite of gSimObject to 1000 updateStage() set playBackCounter to playBackCounter - 1 set status to #idle driveBack(me) else if programmedMove = #enterBridge then set programmedMove to #leaveBridge moveTruck(gTruckObject, exitBridgeDir) set the obstacleState of gSimObject to EMPTY go(the frame) else set availableMoveList to createAvailableList(gTruckObject, cell) refreshControls(availableMoveList) set the tileType of cellObject to #Road if connectedBuildingCell = 0 then set the tileNum of cellObject to getProp(the partialTileList of gSimObject, newMove) else redrawCell(connectedBuildingCell, the stampSprite of gSimObject) end if redrawCell(cellObject, the destinationSprite of gSimObject) updateStage() if not connectedBuildingCell = 0 then set the buildingsConnected of gSimObject to the buildingsConnected of gSimObject + 1 playSound(buildingSound) end if set doneFlag to 0 repeat with adjVector in the adjacentList of cellObject set adjCell to cell + getProp(the moveList of gSimObject, adjVector) if adjCell = the goalCell of gSimObject then set newMove to adjVector add(the recordedMoveList of gSimObject, newMove) set doneFlag to 1 exit repeat end if end repeat flushBuffer() if doneFlag = 1 then set programmedMove to #finalRotation rotateSprite(me, lastMove, newMove) else set stuckFlag to areYouStuck(cell, availableMoveList) if stuckFlag <> 1 then if the level of gLevelObject = 3 then if the gasLevel of gGasGaugeObject < 1 then hideControls() updateStage() set outOfGasFlag to 1 outOfGasAlert() end if end if if outOfGasFlag <> 1 then placeInvisibleButtons(gSimObject, availableMoveList, 1) end if end if if programmedMove = #leaveBridge then set programmedMove to 0 go(the frame + 1) abort() end if end if end if end if end on finishedRoad me fixTile(gSimObject) set goalObj to getAt(the cellList of gSimObject, the goalCell of gSimObject) set oppositeDir to getProp(the convertList of gSimObject, newMove) set the tileNum of goalObj to the tileNum of goalObj + 8 + getPos(the arrowList of gSimObject, oppositeDir) redrawCell(goalObj, the stampSprite of gSimObject) set the tileNum of cellObject to the roadTile1 of gSimObject + getProp(getProp(the tileList of gSimObject, lastMove), newMove) redrawCell(cellObject, the destinationSprite of gSimObject) puppetSound("HERE") hideControls() updateStage() set lastMove to getLast(the recordedMoveList of gSimObject) set the truck1 of gSimObject to the returnVehicle of gSimObject preloadVehicle(me, the truck1 of gSimObject) set the castNum of sprite channel to the truck1 of gSimObject + (5 * (getPos(the arrowList of gSimObject, lastMove) - 1)) updateStage() repeat while soundBusy(1) end repeat puppetSound(0) set playBack to 1 set playBackCounter to count(the recordedMoveList of gSimObject) - 1 driveBack(me) end on driveBack me if playBackCounter >= 2 then set newMove to getAt(the recordedMoveList of gSimObject, playBackCounter) set nextCell to cell + getProp(the moveList of gSimObject, newMove) set nextCellObject to getAt(the cellList of gSimObject, nextCell) surroundSprite(cell, newMove) updateStage() redrawCell(cellObject, the underTruckSprite of gSimObject) redrawCell(nextCellObject, the destinationSprite of gSimObject) updateStage() set programmedMove to #driveBack rotateSprite(me, lastMove, newMove) else set newMove to getAt(the recordedMoveList of gSimObject, 1) surroundSprite(cell, newMove) redrawCell(cellObject, the underTruckSprite of gSimObject) redrawCell(getAt(the cellList of gSimObject, the startCell of gSimObject), the destinationSprite of gSimObject) updateStage() set programmedMove to #lastMove rotateSprite(me, lastMove, newMove) end if end on fillRoadTile if programmedMove <> #leaveBridge then set filledRoadTile to the roadTile1 of gSimObject + getProp(getProp(the tileList of gSimObject, lastMove), newMove) set the tileNum of cellObject to filledRoadTile + the connector of cellObject end if redrawCell(cellObject, the underTruckSprite of gSimObject) end on rumbleAndShake me, lastMove, latestMove set programmedMove to #turnToImmovable rotateSprite(me, lastMove, latestMove) end on rotateSprite me, oldWay, newWay if oldWay <> newWay then set difference to getPos(the arrowList of gSimObject, newWay) - getPos(the arrowList of gSimObject, oldWay) set status to #animating set currentState to the castNum of sprite channel set animCounter to 1 if difference < 0 then if abs(difference) > 4 then set animationScript to "rotateClockwise( gTruckObject )" set rotationSteps to 5 * (8 - abs(difference)) else set animationScript to "rotateCounterclockwise( gTruckObject )" set rotationSteps to 5 * abs(difference) end if else if abs(difference) > 4 then set animationScript to "rotateCounterclockwise( gTruckObject )" set rotationSteps to 5 * (8 - abs(difference)) else set animationScript to "rotateClockwise( gTruckObject )" set rotationSteps to 5 * abs(difference) end if end if else if (the demoFlag of gSimObject = 1) and (the finishedFlag of gSimObject = 0) then startTimer() repeat while the timer < 5 end repeat end if doneRotating(me) end if end on rotateClockwise me if animCounter <= rotationSteps then set currentState to currentState + 1 if currentState = (the truck1 of gSimObject + 40) then set currentState to the truck1 of gSimObject end if set the castNum of sprite channel to currentState set animCounter to animCounter + 1 puppetTempo(40) else doneRotating(me) end if end on rotateCounterclockwise me if animCounter <= rotationSteps then set currentState to currentState - 1 if currentState < the truck1 of gSimObject then set currentState to the truck1 of gSimObject + 39 end if set the castNum of sprite channel to currentState set animCounter to animCounter + 1 puppetTempo(40) else doneRotating(me) end if end on doneRotating me if (programmedMove = 0) or (programmedMove = #leaveBridge) then afterRotating(me) else if programmedMove = #driveBack then goToNextCell(me) else if programmedMove = #turnToImmovable then sound playFile 1, gCDpath & "SOUND" & gFileSep & "SIM" & gFileSep & "OOPS" & string(random(5)) set programmedMove to #awayFromImmovable rotateSprite(me, latestMove, lastMove) repeat while soundBusy(1) end repeat else if programmedMove = #awayFromImmovable then replaceInvisibleButtons(gSimObject) set status to #idle set programmedMove to 0 else if programmedMove = #finalRotation then set the finishedFlag of gSimObject to 1 repeat with x = 1 to count(the recordedMoveList of gSimObject) setAt(the recordedMoveList of gSimObject, x, getProp(the convertList of gSimObject, getAt(the recordedMoveList of gSimObject, x))) end repeat set programmedMove to 0 finishedRoad(me) else if programmedMove = #lastMove then isRoadFinished(gSimObject) end if end if end if end if end if end if end on preloadVehicle me, firstCast preLoadCast(firstCast, firstCast + 39) end on checkForConnection set connectedBuildingCell to 0 repeat with adjVector in the adjacentList of nextCellObject set adjacentCell to getAt(the cellList of gSimObject, nextCell + getProp(the moveList of gSimObject, adjVector)) if the tileType of adjacentCell = #Building then if the connector of adjacentCell = 0 then set tileName to stripSuffix(the name of cast the tileNum of adjacentCell) set buildingSound to tileName & "Sound" set connectedBuilding to the tileNum of adjacentCell + getPos(the arrowList of gSimObject, adjVector) set the tileNum of adjacentCell to connectedBuilding set the connector of adjacentCell to 1 set roadConnector to getPos(the arrowList of gSimObject, getProp(the convertList of gSimObject, adjVector)) set the tileNum of nextCellObject to getProp(the partialTileList of gSimObject, newMove) + roadConnector set the connector of nextCellObject to roadConnector set x to blockCrossings(nextCell, adjVector) set connectedBuildingCell to adjacentCell exit repeat end if end if end repeat return connectedBuildingCell end on createAvailableList me, cell set adjacentCellList to the adjacentList of getAt(the cellList of gSimObject, cell) set availableMoveList to [] repeat with x = 1 to count(adjacentCellList) add(availableMoveList, getAt(adjacentCellList, x)) end repeat set filledCellList to [] repeat with x = 1 to count(availableMoveList) set adjVector to getAt(availableMoveList, x) set adjCell to cell + getProp(the moveList of gSimObject, adjVector) set adjObj to getAt(the cellList of gSimObject, adjCell) if (the tileType of adjObj = #Road) or (the tileType of adjObj = #Bridge) or (the tileType of adjObj = #Goal) or (the tileType of adjObj = #Building) then add(filledCellList, adjVector) next repeat end if if the tileType of adjObj = #River then if checkBlockage(adjCell, adjObj, adjVector) = 1 then add(filledCellList, adjVector) end if end if end repeat repeat with x = 1 to count(filledCellList) set filledCell to getAt(filledCellList, x) set position to getPos(availableMoveList, filledCell) if position <> 0 then deleteAt(availableMoveList, position) end if end repeat return availableMoveList end on drawTruck me repeat with x = 1 to count(the adjacentList of cellObject) set adjCell to getProp(the moveList of gSimObject, getAt(the adjacentList of cellObject, x)) redrawCell(getAt(the cellList of gSimObject, cell + adjCell), the firstSurroundSprite of gSimObject + x - 1) end repeat updateStage() redrawCell(cellObject, the destinationSprite of gSimObject) set the castNum of sprite channel to the truck1 of gSimObject + (5 * (getPos(the arrowList of gSimObject, newMove) - 1)) set the locH of sprite channel to the Xloc of cellObject set the locV of sprite channel to the Yloc of cellObject updateStage() end on restore me set the locH of sprite channel to the locH of sprite channel - 1000 end on makeBridge me set riverTileName to char 1 of the name of cast the tileNum of blockedCellObj set bridgeData to getProp(getProp(the bridgeList of gSimObject, riverTileName), newMove) set the tileNum of nextCellObject to the bridge1 of gSimObject + getAt(bridgeData, 1) set the tileType of nextCellObject to #Bridge set exitBridgeDir to getAt(bridgeData, 2) end on loadTruck me, index set cell to value(item index of the dataString of gMenuObject) set index to index + 1 set nextCell to value(item index of the dataString of gMenuObject) set index to index + 1 set firstCell to value(item index of the dataString of gMenuObject) set index to index + 1 set previousCell to value(item index of the dataString of gMenuObject) set index to index + 1 set newMove to getAt(the arrowList of gSimObject, value(item index of the dataString of gMenuObject)) set index to index + 1 set lastMove to getAt(the arrowList of gSimObject, value(item index of the dataString of gMenuObject)) set index to index + 1 set startDirection to getAt(the arrowList of gSimObject, value(item index of the dataString of gMenuObject)) set index to index + 1 set cellObject to getAt(the cellList of gSimObject, cell) set Xloc to the Xloc of cellObject set Yloc to the Yloc of cellObject set nextCellObject to getAt(the cellList of gSimObject, nextCell) return index end on saveTruck me repeat with propName in [cell, nextCell, firstCell, previousCell] set truckData to truckData & string(propName) & "," end repeat repeat with propName in [newMove, lastMove, startDirection] set truckData to truckData & string(getPos(the arrowList of gSimObject, propName)) & "," end repeat return truckData end